package com.lightbook.controller;


import com.lightbook.pojo.Book;
import com.lightbook.pojo.Classification;
import com.lightbook.pojo.User;
import com.lightbook.result.Result;
import com.lightbook.service.ClassificationService;
import com.lightbook.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "分类管理")
@RestController
@RequestMapping("/admin/system/classif")
public class ClassificationController {
    @Autowired
    private ClassificationService classificationService;

    //    id查询
    @ApiOperation(value = "id查询")
    @GetMapping("/findAll/{courseId}")
    public Result getTreeNodes(@PathVariable Long courseId){
        List<Classification> list = classificationService.findTeachplayTree(courseId);
        return Result.ok(list);
    }
    //    查询所有
    @ApiOperation(value = "所有")
    @GetMapping("/findAll")
    public Result getTreeNodesAll(){
        List<Classification> list = classificationService.findTeachplayTreeAll();
        return Result.ok(list);
    }

    //   添加
    @ApiOperation(value = "添加")
    @PostMapping("/save")
    public Result save(@RequestBody Classification classification) {
        boolean save = classificationService.save(classification);
        if (save) {
            return Result.ok();
        } else {
            return Result.fail();
        }

    }
    //修改
    @ApiOperation(value = "修改")
    @PutMapping("/update")
    public Result updateById(@RequestBody Classification classification) {
        boolean update = classificationService.updateById(classification);
        if (update) {
            return Result.ok();
        } else {
            return Result.fail();
        }
    }
    //批量删除图书
    @ApiOperation(value = "根据Id批量删除")
    @DeleteMapping("/batchRemove")
    public Result batchRemove(@RequestBody List<Long> idList) {
        classificationService.removeByIds(idList);
        return Result.ok();
    }

}
